// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Data;

namespace SnapObjects.Data
{
    internal class DataTablePackerFormater : IDataPackerFormater
    {
        private readonly bool _changedOnly;
        private readonly DataTable _dataTable;

        public DataTablePackerFormater(DataTable dataTable, bool changedOnly)
        {
            _dataTable = dataTable;
            _changedOnly = changedOnly;
        }

        public object Value => _dataTable;

        public string Format(DataFormat format)
        {
            switch (format)
            {
                case DataFormat.Json:
                    return _dataTable.ExportJson(_changedOnly);

                case DataFormat.Xml:
                    return _dataTable.ExportXml(_changedOnly);

                default: throw new NotSupportedException(format.ToString());
            }
        }
    }
}
